home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13912 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
  2. From: grantp@usa.pipeline.com(Pete Grant)
  3. Newsgroups: comp.lang.c++,
  4. Subject: Re: Why does this work?
  5. Date: 27 Mar 1996 22:46:09 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4jcgfh$fs5@news1.h1.usa.pipeline.com>
  8. References: <DoxvnA.L0C@mail.auburn.edu>
  9. NNTP-Posting-Host: 38.8.60.7
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete Grant)
  13. X-Newsreader: Pipeline v3.5.0
  14.  
  15. On Mar 27, 1996 18:35:33 in article <Why does this work?>,
  16. 'greerjo@mail.auburn.edu (John M. Greer)' wrote: 
  17.  
  18.  
  19. >This is probably a horribly simple question, but I was going through a  
  20. >few books, brushing up on my iostreams, when I saw this tidbit in Jamsa's 
  21.  
  22. >Multimedia Trilogy (The CD-ROM by Kris Jamsa) 
  23. >#include <iostream.h> 
  24. >#include <ctype.h> 
  25. >void main(void) 
  26. >{ 
  27. >char letter; 
  28. >while (! cin.eof()) 
  29. >{ 
  30. >letter = cin.get(); 
  31. >letter = toupper(letter); 
  32. >cout << letter; 
  33. >} 
  34. >} 
  35. >Why does this work!?!?  It seems to reserve storage for only one  
  36. >character in letter, but outputs a whole line at a time.  Feel free to  
  37. >flame my stupidity, but please satisfy my curiosity (I'm really not this  
  38. >clueless, I promise!!) 
  39.  
  40. Ok, ask and ye shall receive.. Consider yourself flamed :-) 
  41.  
  42. Actually, the above code outputs a single character at a time. 
  43. However, you may only see a line at a time as the characters 
  44. are buffered until the system decides it's time to empty 
  45. the buffer.  According to the 'specs', output buffer is 
  46. flushed when an endl or flush manipulator is 'processed',  
  47. or when the output stream is closed.  However, most systems 
  48. flush the buffer when a newline is encountered. 
  49.  
  50. -- 
  51. Pete Grant 
  52. Kalevi, Inc. 
  53. Software Engineering & development
  54.